<html>

<head>
</head>

<body>
<center><h1>Bem vindo ao Blog da 4Linux!!!!</h1></center>
<table border = "0" width="700" cellspacing="0" cellpadding ="0">
<?php
	$doc = new DomDocument();
	$doc->load('blog.xml');
	
	$posts = $doc->getElementsByTagName('post');
	$comentarios = $doc->getElementsByTagName('comentario');
	$totalComentarios = 0;
	foreach($posts as $post){
		$idPost   = $post->getAttribute('idPost');
		$titulo   = $post->getElementsByTagName('titulo')->item(0)->nodeValue;
		$conteudo = $post->getElementsByTagName('conteudo')->item(0)->nodeValue;
		$data     = $post->getElementsByTagName('data')->item(0)->nodeValue;

		foreach($comentarios as $comentario){
			$idPostComentario = $comentario->getAttribute('idPostComentario');
			if($idPost == $idPostComentario){
				$totalComentarios++;
				
			}else{
				$totalComentarios = 0;
			}
		}
		echo "<tr><td width=\"550\"><a href=\"detalhePost.php?idPost={$idPost}\"><h4>{$titulo}</h4></a><td width=\"150\">{$data}<td></tr>
			<tr><td colspan=\"2\"><hr /></td></tr>
			<tr><td width=\"600\" colspan=\"2\"><p>{$conteudo}</p><br /></td></tr>
			<tr><td width=\"600\" colspan=\"2\" style=\"alingh:rigth;\"><a href=\"detalhePost.php?idPost={$idPost}\">Comentar</a>&nbsp;&nbsp;
			Total de Comentarios:{$totalComentarios}</p><br /><br /><br /></td></tr>";


	}

?>
</table>
<body>
</html>